799B - T-shirt buying - CodeForces Solution


data structures implementation *1400

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <utility>

#define ll long long
#define MOD 1000000007

using namespace std;

void solve()
{
	int n; cin >> n;
	vector<int> p(n), a(n), b(n);
	for (int i = 0; i < n; i++)	cin >> p[i];
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];

	int m; cin >> m;
	vector<int> c(m);
	for (int i = 0; i < m; i++) cin >> c[i];

	set<int> r, g, d;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == 1 || b[i] == 1) r.insert(p[i]);
		if (a[i] == 2 || b[i] == 2) g.insert(p[i]);
		if (a[i] == 3 || b[i] == 3) d.insert(p[i]);
	}

	for (auto el : c)
	{
		int price;
		if (el == 1 && r.size())
			price = *r.begin();
		else if (el == 2 && g.size())
			price = *g.begin();
		else if (el == 3 && d.size())
			price = *d.begin();
		else
			price = -1;
		cout << price << " ";
		r.erase(price);
		g.erase(price);
		d.erase(price);
	}

}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); //file input.txt is opened in reading mode i.e "r"
	freopen("output.txt", "w", stdout); //file output.txt is opened in writing mode i.e "w"
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int tc = 1;
	// cin >> tc;
	while (tc--)
		solve();
	return 0;
}



Comments

Submit
0 Comments
More Questions

1426C - Increase and Copy
520C - DNA Alignment
767A - Snacktower
1365A - Matrix Game
714B - Filya and Homework
31A - Worms Evolution
1691A - Beat The Odds
433B - Kuriyama Mirai's Stones
892A - Greed
32A - Reconnaissance
1236D - Alice and the Doll
1207B - Square Filling
1676D - X-Sum
1679A - AvtoBus
1549A - Gregor and Cryptography
918C - The Monster
4B - Before an Exam
545B - Equidistant String
1244C - The Football Season
1696B - NIT Destroys the Universe
1674A - Number Transformation
1244E - Minimizing Difference
1688A - Cirno's Perfect Bitmasks Classroom
219A - k-String
952A - Quirky Quantifiers
451B - Sort the Array
1505H - L BREAK into program
171E - MYSTERIOUS LANGUAGE
630D - Hexagons
1690D - Black and White Stripe